package com.erp.main.controller;

import com.erp.common.result.Result;
import com.erp.main.service.UserService;
import com.erp.model.entity.User;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public Result getAll(){

        PageInfo<User> userPageInfo = userService.getAll(null);

        return Result.ok(userPageInfo);
    }

    @PostMapping
    public Result addUser(@RequestBody User user){

        userService.insert(user);

        return Result.ok();
    }


    @PutMapping
    public Result updateUser(@RequestBody User user){

        userService.updateById(user);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    public Result deleteUser(@PathVariable Long id){
        userService.deleteById(id);
        return Result.ok();
    }

}
